package com.yangyang.lamviarm.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class JClient {

	public static void swamp(Integer a, Integer b) {
		int temp = a;
		a = new Integer(b);
		b = new Integer(temp);
		System.out.println("swamp   a = :" + a + ", b= :" + b);
	}

	public static void main(String[] args) {
		try {
			Socket client = new Socket("localhost", 10086);
			final BufferedReader reader = new BufferedReader(
					new InputStreamReader(client.getInputStream()));
			BufferedReader sysreader = new BufferedReader(
					new InputStreamReader(System.in));
			PrintWriter writer = new PrintWriter(client.getOutputStream());
			System.out.println("client is running...");
			new Thread() {
				@Override
				public void run() {
					while (true) {
						try {
							String line = reader.readLine();
							if (line == null || line.equals("exit")
									|| line.equals("bye"))
								break;
							System.out.println("server result:" + line);
						} catch (IOException e) {
							e.printStackTrace();
							break;
						}
					}
				}
			}.start();
			while (true) {
				String line = sysreader.readLine();
				writer.println(line);
				writer.flush();
				if (line.equals("exit") || line.equals("byte")) {
					break;
				}
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
